<template>
    <div class="dashboard-container">
        <my-search :fields="fieldsList" :baseNumber="6" @onSearch="searchForm" @onReset="resetForm" :selectIsAddAll="false" />
        <div class="btn">

        </div>
        <div class="table-list" v-if="showTable">

            <el-table v-loading="loading" :data="tableDatas" border fit :height="$store.state.app.windowHeight - 160" max-height="660px">
                <el-table-column type="index" label="序号" width="60" align="center" :index="currIndex"> </el-table-column>
                <el-table-column v-for="(item,key) in tableColumns" :key="key" :label="item.label" :prop="item.prop" :align="item.align" :width="item.width?item.width:''" :min-width="item.minWidth"></el-table-column>

            </el-table>
        </div>
    </div>
</template>

<script>
import { mapGetters } from 'vuex'
import { queryList } from '@/api/cxtj/qyndrkfx'
import {
    queryDetailList
} from '@/api/cxtj/zdsygl'
export default {
    name: 'qyndrkfx',

    data() {
        return {
            loading: false,
            showTable: true,
            fieldsList: [
                {
                    label: '纳税人名称',
                    field: 'qymc',
                    type: 'autocomplete',
                    value: '',
                    options: []
                },
                {
                    label: '纳税人识别号',
                    field: 'shxydm',
                    type: 'text',
                    value: ''
                },
                {
                    label: '年度',
                    field: 'date',
                    type: 'yearrange', // daterange
                    value: [],
                },
                {
                    label: '征收项目:',
                    field: 'zsxmDm',
                    type: 'select',
                    value: '',
                    options: [



                        {
                            label: '增值税',
                            value: '10101'
                        },
                        {
                            label: '消费税',
                            value: '10102'
                        },
                        {
                            label: '营业税',
                            value: '10103'
                        },
                        {
                            label: '企业所得税',
                            value: '10104'
                        },
                        {
                            label: '资源税',
                            value: '10107'
                        },
                        {
                            label: '城市维护建设税',
                            value: '10109'
                        },
                        {
                            label: '房产税',
                            value: '10110'
                        },
                        {
                            label: '印花税',
                            value: '10111'
                        },
                        {
                            label: '城镇土地使用税',
                            value: '10112'
                        },
                        {
                            label: '土地增值税',
                            value: '10113'
                        },
                        {
                            label: '车船税',
                            value: '10114'
                        },
                        {
                            label: '车辆购置税',
                            value: '10116'
                        },
                        {
                            label: '耕地占用税',
                            value: '10118'
                        },
                        {
                            label: '契税',
                            value: '10119'
                        },
                        {
                            label: '烟叶税',
                            value: '10120'
                        },
                        {
                            label: '环境保护税',
                            value: '10121'
                        },
                        {
                            label: '其他收入',
                            value: '30799'
                        },
                        {
                            label: '教育费附加',
                            value: '30203'
                        },
                        {
                            label: '国有土地使用权出让收入',
                            value: '30148'
                        },
                        {
                            label: '地方教育附加',
                            value: '30127'
                        },
                        {
                            label: '残疾人就业保障金',
                            value: '30218'
                        },
                    ]
                },

                {
                    label: '征收品目:',
                    field: 'zspmDm',
                    type: 'select',
                    value: '',
                    options: []
                },


            ],
            //右侧表格开始
            tableColumns: [
                {
                    label: '征收项目',
                    prop: 'ZSXMDM',
                    align: 'center',
                    halign: 'center',
                    minWidth: 120,
                    isShow: true,
                },
                {
                    label: '征收品目',
                    prop: 'ZSPMDM',
                    align: 'center',
                    minWidth: 120,
                    isShow: true,
                }

            ],
            tableDatas: []
            , queryObj: {
                qymc: '中国石化河北炼油化工有限公司', //公司名称
                shxydm: '91460000754358922D',
                date: [],

                zsxmDm: '',
                zspmDm: '',
                pageNo: 1,
                pageSize: 20
            },
            total: 0,
            newtableColumns: [],
            searchTxt: '',
            zsxmFlag: false
        }
    },
    computed: {
        ...mapGetters([
            'name'
        ])
    },
    watch: {
        fieldsList: {
            handler(newOption, oldOption) {
                this.searchTxt = newOption[0].value
                if (newOption[3].value == '10111') {
                    this.zsxmFlag = true
                } else {
                    this.zsxmFlag = false
                }
            },
            deep: true
        },
        zsxmFlag(newOption, oldOption) {
            if (newOption == true) {
                this.fieldsList[4].options = [
                    { label: '购销合同', value: '101110101' },
                    { label: '加工承揽合同', value: '101110102' },
                    { label: '建设工程勘察设计合同', value: '101110103' },
                    { label: '建筑安装工程承包合同', value: '101110104' },
                    { label: '财产租赁合同', value: '101110105' },
                    { label: '货物运输合同(按运输费用万分之五贴花)', value: '101110106' },
                    { label: '仓储保管合同', value: '101110107' },
                    { label: '借款合同', value: '101110108' },
                    { label: '财产保险合同', value: '101110109' },
                    { label: '技术合同', value: '101110110' },

                    { label: '产权转移书据', value: '101110200' },

                    { label: 'A种股票', value: '101110301' },
                    { label: 'B种股票', value: '101110302' },
                    { label: '非交易转让股票A种股票', value: '101110303' },
                    { label: '非交易转让股票B种股票', value: '101110304' },
                    { label: '无偿划拨国有股权的股数', value: '101110305' },
                    { label: '社保基金证券交易A种股票印花税', value: '101110306' },
                    { label: '社保基金证券交易B种股票印花税', value: '101110307' },
                    { label: '权利、许可证照', value: '101110400' },
                    { label: '营业帐簿', value: '101110500' },
                    { label: '营业帐簿', value: '101110500' },
                    { label: '资金账簿', value: '101110501' },
                    { label: '其他营业账簿', value: '101110599' },
                    { label: '其他凭证', value: '101119800' },
                    { label: '滞纳金', value: '101119901' },
                    { label: '罚款', value: '101119902' },
                    { label: '利息收入', value: '101119903' },



                ]
            } else {
                this.fieldsList[4].options = []
            }
        },
        searchTxt(newOption, oldOption) {
            this.getQueryDetailList(newOption)
        }
    },
    mounted() {
        // this.getTableData();
    },
    methods: {
        getQueryDetailList(nsrmc) {
            queryDetailList({ nsrmc: nsrmc }).then(res => {
                if (res.code == 200) {
                    this.fieldsList[0].options = res.data.records.map(item => {
                        return { value: item.NSRMC, label: item.NSRMC }
                    })
                }
            })
        },
        searchForm(params) {
            console.log(params, '查询条件');
            this.queryObj.qymc = params.qymc || '';
            this.queryObj.shxydm = params.shxydm || '';
            this.queryObj.date = params.date || [];

            this.queryObj.zsxmDm = params.zsxmDm || '';
            this.queryObj.zspmDm = params.zspmDm || '';

            this.getTableData();
        },
        resetForm() {
            for (let key in this.queryObj) {
                if (key == 'pageNo') {
                    this.queryObj[key] = 1;
                } else if (key == 'pageSize') {
                    this.queryObj[key] = 20;
                } else {
                    this.queryObj[key] = '';
                }
            }
            this.tableDatas = []
            // this.getTableData();
        },
        getTableData() {

            if (this.queryObj.qymc == '') {
                this.$message.error('请输入纳税人名称！')
            } else if (this.queryObj.date.length < 2) {
                this.$message.error('请选择开始年度和结束年度！')
            } else {
                this.tableColumns = [
                    {
                        label: '征收项目',
                        prop: 'ZSXMDM',
                        align: 'center',
                        halign: 'center',
                        minWidth: 120,
                        isShow: true,
                    },
                    {
                        label: '征收品目',
                        prop: 'ZSPMDM',
                        align: 'center',
                        minWidth: 120,
                        isShow: true,
                    }
                ]




                let params = {
                    qymc: this.queryObj.qymc,
                    shxydm: this.queryObj.shxydm,
                    zsxmDm: this.queryObj.zsxmDm,
                    zspmDm: this.queryObj.zspmDm,
                    ksnd: this.queryObj.date[0],
                    jsnd: this.queryObj.date[1],
                }
                this.loading = true
                queryList(params).then(res => {
                    console.log(res)
                    this.loading = false
                    for (let i = this.queryObj.date[0]; i <= this.queryObj.date[1]; i++) {
                        this.tableColumns.push({
                            label: i + '',
                            prop: i + '',
                            isShow: true,
                            align: 'center',
                            minWidth: 120
                        })
                    }
                    this.tableDatas = res.data
                })
            }


        },
        changepageNo(currPage) {
            this.queryObj.pageNo = currPage;
            this.getTableData();
        },
        changePageSize(pageSize) {
            this.queryObj.pageSize = pageSize;
            this.getTableData();
        },
        currIndex(index) {
            return index + 1;
        },
    }
}
</script>

<style lang="scss" scoped>
.dashboard-container {
    height: 100%;
    width: 100%;
    background-color: #fff;
    padding: 8px;

    .btn {
        padding: 8px 8px 8px 0;
    }
}
::v-deep .year-range-picker .year-picker {
    max-width: 80px;
}
</style>
